package com.yaoli.niuke;

import com.yaoli.ajob.TreeNode;

/**
 * Created by siemens on 5/31/2017.
 */
public class _018_Test {

    boolean is = true;

    public boolean IsBalanced_Solution(TreeNode root) {
        calc(root);
        return is;
    }

    public int calc(TreeNode node){
        if(node != null){
            int left = calc(node.left);
            int right = calc(node.right);

            if(Math.abs(left - right) > 1){
                is = false;
            }

            return Math.max(left,right) + 1;

        }else{
            return 0;
        }
    }
}
